<div {{ $attributes->class('layui-tab layui-tab-brief status-bar') }} id="{{$name}}"
     lay-filter="{{$name}}">
    <ul class="layui-tab-title">
        <li data-id="" @if($value=='') class="layui-this" @endif>{{$allText}}<span class="layui-badge">0</span></li>
        @if(!empty($kv))
            @foreach($kv as $k=>$text)
                <li data-id="{{$k}}" @if($value==$k) class="layui-this" @endif>{{$text}}<span
                        class="layui-badge">0</span></li>
            @endforeach
        @endif
    </ul>
</div>
@push('script')
    <script type="text/javascript">

        layui.use(['element'], function () {
            layui.element.on('tab({{$name}})', function (data) {
                SystemUtil.adminListTable.tableInc.reload({
                    where: {
                        {{$name}}: data.elem.context.dataset.id
                    }
                });
            });

            function show(statistics) {
                if (statistics) {
                    layui.$("#{{$name}} li[data-id=''] span").text(statistics.all);
                    @if(!empty($kv))
                    @foreach($kv as $k=>$text)
                    layui.$("#{{$name}} li[data-id='{{$k}}'] span").text(statistics[{{$k}}] || 0);
                    @endforeach
                    @endif
                }
            }


            function loadData() {
                let _data = {};
                let params = '{!! json_encode(\Illuminate\Support\Facades\Request::all())!!}';
                let m = JSON.parse(params);

                if (m.searchType) {
                    layui.$.each(m, function (k, v) {
                        console.log(k, v)
                        _data[k] = v;
                    })
                } else {
                    layui.$('#{{$searchFormId}}').serializeArray().forEach(function (item) {
                        _data[item.name] = item.value;
                    });
                    layui.$('#fast-search >> form').serializeArray().forEach(function (item) {
                        _data[item.name] = item.value;
                    });
                }

                @if(!empty($dynamicWhere))
                    _data = layui.$.extend(true, {}, _data, {{$dynamicWhere}}());
                @endif
                SystemUtil.ajax("{{$url}}","GET").setData(_data).send(1)
                    .then((res) => {
                        SystemUtil.resultFilter(res, function (res) {
                            show(res.data);
                        })
                    });
            }

            layui.$('[lay-filter="searchForm"]').click(function () {
                loadData();
            });
            loadData();
            if (!window.statusBar) {
                window.statusBar = {};
            }
            window.statusBar.{{$name}} = {
                load: loadData
            };
        });
    </script>
@endpush
